package cn.kgc.itrip.common;

import net.sourceforge.pinyin4j.PinyinHelper;
import org.apache.log4j.Logger;

import java.util.Arrays;

/**
 * 汉字转拼音的工具类
 */
public class ChineseToEnglish {

    static Logger logger=Logger.getLogger(ChineseToEnglish.class);

    public static String getPinYin(String word){

        StringBuilder sb=new StringBuilder();
        for(int i=0;i<word.length();i++) {
            char c = word.charAt(i);
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c);
            logger.info("word:" + word + " pingyin:" + pinyinArray[0].substring(0, pinyinArray[0].length() - 1));
            System.out.println(Arrays.toString(pinyinArray));
            sb.append( pinyinArray[0].substring(0, pinyinArray[0].length() - 1));
        }
        return sb.toString();
    }

    public static void main(String args[]){
        String result=getPinYin("北京天安门");
        System.out.println("result:"+result);
    }
}